/*=============================================================================

  Application UI MODULE

  FILE: UI.cpp
  
  DESCRIPTION

    Application UI Module

  EXTERNALIZED FUNCTIONS


   Copyright (c) DaeSung Engineering Inc. All rights reserved.

=============================================================================*/
/*=============================================================================

  EDIT HISTORY

  ---------  -------  -------------------------------------------------------
    when       who       what, where, why
  ---------  -------  -------------------------------------------------------
   03/14/04   nso4th    Initial version

=============================================================================*/

/*=============================================================================
  HEADER INCLUSION
=============================================================================*/
#include <Cust_AppDef.h>
#include <mainFrm.h>

/*=============================================================================
  LOCALIZED VARIABLE DEFINITION
=============================================================================*/
static GMsgBox_Style_s		mbox_style =
{
	0,
	// Box info
	UIcolor_TBL(UICOL_BKGND), GC_RED,
	8, 8, 400, 220,
	// Title Info
	150, 30, UIfont_TBL(UIFONT_NORMAL), FW_BOLD,
	// Message info.
	UIcolor_TBL(UICOL_TXT),
	380, 30, UIfont_TBL(UIFONT_MEDIUM), FW_BOLD,
	// Button info
	UIcolor_TBL(UICOL_BTN_FACE), UIcolor_TBL(UICOL_BTN_TEXT),
	100, 50, UIfont_TBL(UIFONT_NORMAL), FW_BOLD
};

/*=============================================================================
  EXTERNALIZED FUNCION DEFINITION
=============================================================================*/
/*---------------------------------------------------------
  MESSAG BOX
---------------------------------------------------------*/
void MBOX_INFO(const char *pszStr)
{
	GMsgBox			dlg((CWnd*)ObjList_Get(VIEW_MAINFRAME));

	NBOX_HIDE();
		
	mbox_style.style = GMB_INFO_T | GMB_OK_T/* | GMB_KORLANG_T*/;
	
	dlg.Set_Style(&mbox_style);
	dlg.Set_MSG(pszStr);
	dlg.DoModal();
}

void MBOX_WARN(const char *pszStr)
{
	GMsgBox			dlg((CWnd*)ObjList_Get(VIEW_MAINFRAME));

	NBOX_HIDE();
	
	mbox_style.style = GMB_WARN_T | GMB_OK_T/* | GMB_KORLANG_T*/;

	dlg.Set_Style(&mbox_style);
	dlg.Set_MSG(pszStr);
	dlg.DoModal();
}

void MBOX_ERR(const char *pszStr)
{
	GMsgBox			dlg((CWnd*)ObjList_Get(VIEW_MAINFRAME));

	NBOX_HIDE();
	
	mbox_style.style = GMB_ERR_T | GMB_OK_T/* | GMB_KORLANG_T*/;
	dlg.Set_Style(&mbox_style);
	dlg.Set_MSG(pszStr);
	dlg.DoModal();
}

BOOL MBOX_YESNO(const char *pszStr)
{
	GMsgBox			dlg((CWnd*)ObjList_Get(VIEW_MAINFRAME));
	int32			ret;

	NBOX_HIDE();
	
	mbox_style.style = GMB_INFO_T | GMB_YESNO_T/* | GMB_KORLANG_T*/;
	

	dlg.Set_Style(&mbox_style);
	dlg.Set_MSG(pszStr);
	ret = dlg.DoModal();

	if(ret == GMB_YES_R)
		return	TRUE;

	return	FALSE;
}

BOOL MBOX_YESNO_WARN(const char *pszStr)
{
	GMsgBox			dlg((CWnd*)ObjList_Get(VIEW_MAINFRAME));
	int32			ret;

	NBOX_HIDE();
	
	mbox_style.style = GMB_WARN_T | GMB_YESNO_T/* | GMB_KORLANG_T*/;
	

	dlg.Set_Style(&mbox_style);
	dlg.Set_MSG(pszStr);
	ret = dlg.DoModal();
	if(ret == GMB_YES_R)
		return	TRUE;

	return	FALSE;
}


void MBOX_INFO2(const char *msg1, const char *msg2)
{
	GMsgBox			dlg((CWnd*)ObjList_Get(VIEW_MAINFRAME));

	NBOX_HIDE();
	
	mbox_style.style = GMB_INFO_T | GMB_OK_T | GMB_MSG2_T/* | GMB_KORLANG_T*/;
	
	
	dlg.Set_Style(&mbox_style);
	dlg.Set_MSG2(msg1, msg2);
	dlg.DoModal();
}

void MBOX_WARN2(const char *msg1, const char *msg2)
{
	GMsgBox			dlg((CWnd*)ObjList_Get(VIEW_MAINFRAME));

	NBOX_HIDE();
	
	mbox_style.style = GMB_WARN_T | GMB_OK_T | GMB_MSG2_T/* | GMB_KORLANG_T*/;
	

	dlg.Set_Style(&mbox_style);
	dlg.Set_MSG2(msg1, msg2);
	dlg.DoModal();
}

void MBOX_ERR2(const char *msg1, const char *msg2)
{
	GMsgBox			dlg((CWnd*)ObjList_Get(VIEW_MAINFRAME));

	NBOX_HIDE();
	
	mbox_style.style = GMB_ERR_T | GMB_OK_T | GMB_MSG2_T/* | GMB_KORLANG_T*/;
	

	dlg.Set_Style(&mbox_style);
	dlg.Set_MSG2(msg1, msg2);
	dlg.DoModal();
}

BOOL MBOX_YESNO2(const char *msg1, const char *msg2)
{
	GMsgBox			dlg((CWnd*)ObjList_Get(VIEW_MAINFRAME));
	int32			ret;

	NBOX_HIDE();
	
	mbox_style.style = GMB_INFO_T | GMB_YESNO_T | GMB_MSG2_T/* | GMB_KORLANG_T*/;
	

	dlg.Set_Style(&mbox_style);
	dlg.Set_MSG2(msg1, msg2);
	ret = dlg.DoModal();

	if(ret == GMB_YES_R)
		return	TRUE;

	return	FALSE;
}

BOOL MBOX_YESNO_WARN2(const char *msg1, const char *msg2)
{
	GMsgBox			dlg((CWnd*)ObjList_Get(VIEW_MAINFRAME));
	int32			ret;

	NBOX_HIDE();
	
	mbox_style.style = GMB_WARN_T | GMB_YESNO_T | GMB_MSG2_T/* | GMB_KORLANG_T*/;
	

	dlg.Set_Style(&mbox_style);
	dlg.Set_MSG2(msg1, msg2);
	ret = dlg.DoModal();
	if(ret == GMB_YES_R)
		return	TRUE;

	return	FALSE;
}

/*---------------------------------------------------------
  NOTI. BOX CONTROL
---------------------------------------------------------*/
typedef struct
{
	char		*title;
	char		*msg;
	int32	noti_time;
} ui_noti_info_s;

void NBOX_REQ(const char *title, const char *msg, u_int32 noti_time)
{
	ui_noti_info_s			nmsg;

	memZeros(&nmsg, sizeof(nmsg));
	
	nmsg.title = (char*)title;
	nmsg.msg = (char*)msg;
	nmsg.noti_time = noti_time;
	EHandler_SendEvent(UI_DEV, UI_NOTIREQ_E, (dword)&nmsg, 0);
	memZeros(&nmsg, sizeof(nmsg));
}

void NBOX_DISP(mcxt noti_msg)
{
	ui_noti_info_s			*nmsg = (ui_noti_info_s*)noti_msg;

	if(nmsg == NULL)
		return;

	NBOX_SHOW(nmsg->title, nmsg->msg, nmsg->noti_time);
}

void NBOX_SHOW(const char *title, const char *msg, u_int32 disp_time)
{
	CMainView		*vw = (CMainView*)ObjList_Get(VIEW_MAIN);
	GNotiBox			*nb;
	static GNotiBox_Style_s		nbox_style =
	{
		// Box info
		GC_RGB(64,32,64), GC_GRAY_LIGHT,
		8, 8, 400, 220,
		// Title Info
		GC_GRAY_DARK, GC_WHITE,
		150, 30, UIfont_TBL(UIFONT_NORMAL), FW_BOLD,
		// Counter info
		GC_GRAY_LIGHT,
		40, 40, UIfont_TBL(UIFONT_BIG)-5, FW_BOLD,
		// Message info.
		GC_YELLOW,
		380, 50, UIfont_TBL(UIFONT_MEDIUM)+1, FW_BOLD,
		// Button info
		GC_RGB(64,32,64), GC_WHITE,
		100, 50, UIfont_TBL(UIFONT_NORMAL), FW_BOLD
	};

	if(vw == NULL)
		return;

	nb = &vw->m_vwNoti;
	if(::IsWindow(nb->m_hWnd) == FALSE)
	{
		nb->Set_Style(&nbox_style);
		nb->WindowCreate(vw);
		nb->Set_BTN("OK");
	}
	nb->Set_Title(title);
	nb->Set_MSG(msg);
	nb->Show(TRUE);
	nb->Set_Timer(disp_time);
}

void NBOX_HIDE(void)
{
	CMainView		*vw = (CMainView*)ObjList_Get(VIEW_MAIN);
	GNotiBox			*nb;

	if(vw == NULL)
		return;

	nb = &vw->m_vwNoti;
	if(::IsWindow(nb->m_hWnd) == FALSE)
		return;

	nb->Show(FALSE);
}

/*---------------------------------------------------------
  STRING FOR COMMON USAGE
---------------------------------------------------------*/
char *UIstring_(char *str, const char *pszFile, int32 nLine)
{
	if(str == NULL)
	{
		return	(char*)memCalloc_(UI_STRING_LEN,pszFile,nLine);
	}
	else
	{
		memFree_(str,pszFile,nLine);
	}

	return	NULL;
}

//--------------------------------------------------------------
// BITMAP OPERRATION	// --- 2014.01.15 jyko Add
//--------------------------------------------------------------
void Bmp_Transparent(CDC *pDC, u_int32 bmpID, COLORREF colBK, COLORREF colDEL, int32 sx, int32 sy)
{
	CDC			m_dcBkg, *m_pBitmapDC;
	CBitmap		m_bmpBkg, m_pBitmap1;
	BITMAP		bmsize;
	
	{
		CRect		rcClient;
		GetClientRect(NULL, &rcClient);

		m_pBitmap1.LoadBitmap(bmpID);
		m_dcBkg.CreateCompatibleDC(pDC);
		m_bmpBkg.CreateCompatibleBitmap(pDC, rcClient.Width(), rcClient.Height());
		CBitmap		*m_pbmpBkgOld = m_dcBkg.SelectObject(&m_bmpBkg);
		m_dcBkg.BitBlt(0, 0, rcClient.Width(), rcClient.Height(), pDC, 0, 0, SRCCOPY);
		m_pBitmap1.GetBitmap(&bmsize);

		m_pBitmapDC = new CDC;
		m_pBitmapDC->CreateCompatibleDC(pDC);
		CBitmap		*pOldSrcBitmap = m_pBitmapDC->SelectObject(&m_pBitmap1);
	}

	CDC			SrcDC;
	CBitmap		srcBmp;

	SrcDC.CreateCompatibleDC(pDC);
	srcBmp.CreateCompatibleBitmap(pDC, bmsize.bmWidth, bmsize.bmHeight);
	SrcDC.SelectObject(&srcBmp);
	SrcDC.BitBlt(0, 0, bmsize.bmWidth, bmsize.bmHeight, m_pBitmapDC, 0, 0, SRCCOPY);

	CDC			maskDC;
	CBitmap		maskBmp;

	maskDC.CreateCompatibleDC(&SrcDC);
	maskBmp.CreateBitmap(bmsize.bmWidth, bmsize.bmHeight, 1, 1, NULL);
	CBitmap		*pOldMaskBmp = maskDC.SelectObject(&maskBmp);

	SrcDC.SetBkColor(colDEL);
	maskDC.BitBlt(0, 0 ,bmsize.bmWidth, bmsize.bmHeight, &SrcDC, 0, 0, SRCCOPY);

	SrcDC.SetBkColor(colBK);
	SrcDC.SetTextColor(GC_WHITE);
	SrcDC.BitBlt(0, 0, bmsize.bmWidth, bmsize.bmHeight, &maskDC, 0, 0, SRCAND);

	CDC			memDC;
	CBitmap		memBmp;

	memDC.CreateCompatibleDC(pDC);
	memBmp.CreateCompatibleBitmap(pDC, bmsize.bmWidth, bmsize.bmHeight);
	CBitmap		*pOldMemBmp = memDC.SelectObject(&memBmp);

	memDC.BitBlt(0, 0, bmsize.bmWidth, bmsize.bmHeight, &m_dcBkg, 0, 0, SRCCOPY);
	memDC.SetBkColor(GC_WHITE);
	memDC.BitBlt(0, 0, bmsize.bmWidth, bmsize.bmHeight, &maskDC, 0, 0, SRCAND);
	memDC.BitBlt(0, 0, bmsize.bmWidth, bmsize.bmHeight, &SrcDC, 0, 0, SRCPAINT);
	pDC->BitBlt(sx, sy, bmsize.bmWidth, bmsize.bmHeight, &memDC, 0, 0, SRCCOPY);

	memDC.SelectObject(pOldMemBmp);
	delete m_pBitmapDC;
}

/*--- END OF UI.cpp ---*/
